﻿using System;
using System.Windows;
using System.Windows.Controls;
using Asko.Lib.ViewModels;
using System.ComponentModel;
using System.Windows.Media;
using GalaSoft.MvvmLight.Messaging;
using Asko.Lib.Messages;

namespace Asko.Lib.Views
{
    public delegate void DisposingHandler(object sender);

    public class NodeView : Control, IDisposable
    {
        #region Champs
        #endregion

        #region Evenements
        public event DisposingHandler Disposing;
        #endregion

        #region Méthodes
        public NodeView()
        {
            this.DataContextChanged += new DependencyPropertyChangedEventHandler(NodeView_DataContextChanged);           
        }
        static NodeView()
        {
            //override the StyleKey Property
            DefaultStyleKeyProperty.OverrideMetadata(typeof(NodeView), new FrameworkPropertyMetadata(typeof(NodeView)));
        }
        /// <summary>
        /// Se produit lorsque le contexte des données de cet élément change. 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void NodeView_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            NodeViewModel _nvmModeleVue;

            if (e.NewValue != null)
            {
                _nvmModeleVue = e.NewValue as NodeViewModel;
                _nvmModeleVue.View = this;
               
            }
        }
        /// <summary>
        /// 
        /// </summary>
        public void Dispose()
        {
            if (Disposing != null)
                Disposing(this);
        }

        #endregion

        #region Propriétés
        public static readonly DependencyProperty XProperty =
            DependencyProperty.RegisterAttached("X",
                typeof(double),
                typeof(NodeView),
                new UIPropertyMetadata());
        public double X
        {
            get { return (double)GetValue(XProperty); }
            set { SetValue(XProperty, value); }
        }
        public static readonly DependencyProperty YProperty =
            DependencyProperty.RegisterAttached("Y",
        typeof(double),
        typeof(NodeView),
        new UIPropertyMetadata());
        public double Y
        {
            get { return (double)GetValue(YProperty); }
            set
            {
                SetValue(YProperty, value);
            }
        }
        #endregion
    }
}
